package com.happy.common.util;

import java.math.BigDecimal;
import java.util.Random;

public final class RandNumber {
	private static char[] INTMAP = { '9', '1', '4', '3', '2', '5', '8', '6',
			'7', '0' };

	private static char[] CHARMAP = { 'z','D', 's', 'g', '4', '5','G', '3', 'h', 'd',
			'8', 'm','V', 'a', 'b', 'c','K', '7', 'e', 'f', '2', '6','B', 'i', 'j', 'k',
			'l','X', '9', 'n', 'o', 'p', 'q', 'r', '1', 't', 'u', 'v', 'w', 'x',
			'x', 'y', '0','A','F','Z','E','J','L','R','T','S' };

	// ����һ������
	public static int getInt() {
		Random ran = new Random();
		char[] valueCs = String.valueOf(Math.abs(ran.nextInt())).toCharArray();
		System.out.println(String.valueOf(valueCs));
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < valueCs.length; i++) {
			buffer.append(INTMAP[Integer.parseInt(String.valueOf(valueCs[i]))]);
		}
		return Integer.parseInt(String.valueOf(buffer.toString()));
	}

	// ����ָ��λ�������
	public static int getInt(int length) {
		if (length >= 10 || length <= 0)
			return length;
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < length; i++) {
			buffer.append(INTMAP[Integer.parseInt(FileExtenstion
					.beforeExtenstion(String.valueOf(INTMAP.length
							* Math.random())))]);
		}
		return Integer.parseInt(buffer.toString());
	}

	// ����ָ������ڵ������
	public static int getInt(int begin, int end) {
		return (int) (Math.random() * (end - begin + 1)) + begin;
	}

	// ����һ���ַ� ������
	public static String getString() {

		String value = FileExtenstion.getFileExtenstion(String.valueOf(Math
				.random()));
		char[] chCs = value.toCharArray();
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < chCs.length; i++) {
			buffer.append(CHARMAP[Integer.parseInt(FileExtenstion
					.beforeExtenstion(String.valueOf(CHARMAP.length
							* Math.random())))]);
		}
		return buffer.toString();
	}

	// ����ָ�����ȵ��ַ�
	public static String getString(int length) {

		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < length; i++) {
			buffer.append(CHARMAP[Integer.parseInt(FileExtenstion
					.beforeExtenstion(String.valueOf(CHARMAP.length
							* Math.random())))]);
		}
		return buffer.toString();
	}

	// ����һ���漴�ĸ�����
	public static double getDouble() {
		return Math.random();
	}

	// ����ָ������ڵ�һ��double���͵����
	public static double getDouble(double begin, double end) {
		return (double) (Math.random() * (end - begin + 1)) + begin;
	}

	// ��һ��double ���͵�����������
	public static double getRoundDouble(double number, int end) {
		BigDecimal b = new BigDecimal(number);
		number = b.setScale(end, BigDecimal.ROUND_HALF_UP).doubleValue();
		return number;
	}

	// ��������һ��float���͵���
	public static float getRoundFloat(float number, int end) {
		BigDecimal b = new BigDecimal(number);
		number = b.setScale(end, BigDecimal.ROUND_HALF_UP).floatValue();
		return number;
	}

	// ����һ��float���͵����
	public static float getFloat() {
		return Float.valueOf(String.valueOf(Math.random())).floatValue();
	}

	// ����һ��ָ������ڵ� float���͵������
	public static float getFloat(int begin, int end) {
		return (float) (Math.random() * (end - begin + 1)) + begin;
	}

	public static void main(String[] args) {
		System.out.println(RandNumber.getRoundFloat(RandNumber.getFloat(1,7),1));
	}

}
